<?php
session_start();
$domain = $_GET['domain'];
mysql_connect("localhost", "", "");
mysql_query("USE stats_syslog");
//$optionsquery = mysql_query("SELECT ReasonExt, COUNT(*) AS count FROM maillog WHERE Action = 'Per-User Quarantine' AND Reason = 'Blacklist' AND Domain = '$domain' GROUP BY ReasonExt ORDER BY count DESC LIMIT 0,10");
$optionsquery = mysql_query("SELECT ReasonExt, COUNT(*) AS count FROM maillog WHERE Reason = 'Blacklist' AND Domain = '$domain' GROUP BY ReasonExt ORDER BY count DESC LIMIT 0,10");
while($row = mysql_fetch_row($optionsquery)) {
    $piece_names_temp[] = $row;
}
mysql_close();
if ($piece_names_temp) {
    foreach ($piece_names_temp as $key => $row) {
         $blacklist_names[$key] = $row[0];
    }
    foreach ($piece_names_temp as $key => $row) {
         $blacklist_values[$key] = $row[1];
    }
    $_SESSION['blacklist_names_.$domain'] = $blacklist_names;
    $_SESSION['blacklist_values_.$domain'] = $blacklist_values;
    echo "<html>";
    echo "<body>";
    echo "<b>Top DNS-Blacklists for Domain \"$domain\"</b><br><br>";
    echo "<table border=1>";
    echo "<tr>";
    echo "<td>DNS-Blacklist</td><td>Number</td>";
    echo "</tr>";
    for ($x = 0; $x < count($blacklist_names); $x++){
      echo "<tr><td>".$blacklist_names[$x]."</td><td>".$blacklist_values[$x]."</td></tr>";
      }
    echo "</table>";
    echo "<br><br><br>";
    echo "<img src=\"topblacklists-diagramm.php?domain\" border=\"0\">";
    echo "</body>";
    echo "</html>";
}
else {
    echo "<html>";
    echo "<body>";
    echo "No entries found!";
    echo "</body>";
    echo "</html>";
}
?>
